//
//  FastFunction.m
//  New_Runway
//
//  Created by NewLife on 2018/2/27.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "FastFunction.h"

CGFloat getRealWidth(CGFloat x) {
    
    CGFloat realWidth = x * Screen_width / 375.0;
    
    if ((int)realWidth == 0) {
        
        return realWidth;
    }
    
    return (int)realWidth;
}

CGFloat getRealHeight(CGFloat x) {
    
    CGFloat realHeight = x * Screen_height / 667.0;
    
    if ((int)realHeight == 0) {
        
        return realHeight;
    }
    
    return (int)realHeight;
}

UIFont *getPingfangFont(CGFloat x) {
    
    CGFloat scale = Screen_width / 375.0;
    
    return [UIFont fontWithName:@"PingFangSC-Regular" size:(int)(scale * x)];
}

UIColor *getColorFromString(NSString *string) {
    
    return [UIColor colorFromHexCode:string];
}

UIImage *getImageFromName(NSString *name) {
    
    return [UIImage imageNamed:name];
}

/**< 是否为字典 数组 */
BOOL isSetClass(id obj) {
    
    return ([obj isKindOfClass:[NSArray class]] || [obj isKindOfClass:[NSDictionary class]]);
}

/**< 是否为数组 */
BOOL isArrayClass(id obj) {
    
    return [obj isKindOfClass:[NSArray class]];
}

/**< 是否为字典 */
BOOL isDictionaryClass(id obj) {
    
    return [obj isKindOfClass:[NSDictionary class]];
}

/**< 判断字符串是否为空 */
BOOL isEmptyOrNilString(NSString *str) {
    
    return (str == nil || str.length == 0 || str == NULL);
}
BOOL isValidUrl(NSString *str)
{
    NSString *regex =@"[a-zA-z]+://[^\\s]*";
    NSPredicate *urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    return [urlTest evaluateWithObject:str];
}
CGFloat getSafeBottomMargin(void) {
    return Screen_height == 812? 34: 0;
}
